//
//  TableHeaderView.m
//  HappyBaby
//
//  Created by lanou on 15/11/24.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "TableHeaderView.h"
#import "Define.h"
#import "CarouselFigureModel.h"
@interface TableHeaderView ()



@end

@implementation TableHeaderView

- (NSMutableArray *)buttonArray
{
    if (_buttonArray == nil) {
        self.buttonArray = [NSMutableArray array];
    }
    return _buttonArray;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //self.backgroundColor = [UIColor cyanColor];
        // 创建轮播图
        CGFloat yScale = frame.size.height / 310;
        CGFloat height = 180 * yScale;
       
        self.carousel = [[CarouselFigure alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
        [self addSubview:_carousel];
        

        CGFloat xScale = frame.size.width / 375;
        CGFloat X = (kScreenWidth - 300 * xScale)/2;
        //CGFloat Y = height + bgViewHeight + 25 * yScale;
        CGFloat Y = height + 25 * yScale;
        CGFloat width = 60 * xScale;
        CGFloat xSpace = width * 2;
        NSArray *picArray = @[@"亲子游戏", @"玩具", @"童书"];
        for (int i = 0; i < 3; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(X + xSpace * i, Y, width, width);
            button.layer.cornerRadius = 20;
            button.layer.masksToBounds = YES;
            button.tag = 100 + i;
            [button setImage:[UIImage imageNamed:picArray[i]] forState:UIControlStateNormal];
            [self addSubview:button];
            [self.buttonArray addObject:button];
            
            // 显示Button标题
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(X + xSpace * i, Y + width + 10*kScaleY, width, 25 * kScaleY)];
            label.textAlignment = NSTextAlignmentCenter;
            label.font = [UIFont systemFontOfSize:kScreenWidth / 28];
            label.textColor = [UIColor darkGrayColor];
            label.text = picArray[i];
            [self addSubview:label];
        }
 
    }
    return self;
}

- (void)setModelArray:(NSArray *)modelArray
{
    if (modelArray) {
        _modelArray = modelArray;

        self.carousel.array = modelArray;
    }
}

@end
